﻿// See https://aka.ms/new-console-template for more information

using Microsoft.CodeAnalysis;
using System;
using System.CodeDom.Compiler;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Reflection.Emit;

namespace ConsoleApp1
{

    class Program
    {
        public static void Main(string[] args)
        {
        
            Simple1.Run();
            Simple2.Run();
            Console.ReadLine();
            Console.ReadLine();
        }
    }
    /*
     
        var methods= typeof(IRoleManage).GetMethods();
            foreach (var method in methods) Console.WriteLine(method.Name);

            AssemblyName assemblyName = new AssemblyName("DynamicCode");
            AssemblyBuilder dynamicAssembly = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndCollect);
            var moduleBuilder = dynamicAssembly.DefineDynamicModule("DynamicCode");
            var typeBuilder = moduleBuilder.DefineType("HelloKittyClass", TypeAttributes.Public);
            typeBuilder.AddInterfaceImplementation(typeof(IRoleManage));
            var methodBuilder = typeBuilder.DefineMethod("Get", MethodAttributes.Public | MethodAttributes.Virtual, typeof(string), new Type[] { typeof(long) });

            // then get the method il generator
            var il = methodBuilder.GetILGenerator();

            var requestMessage = il.DeclareLocal(typeof(System.Net.Http.HttpRequestMessage));
            var responseMessage = il.DeclareLocal(typeof(System.Net.Http.HttpResponseMessage));

            il.Emit(OpCodes.Nop);
            il.Emit(OpCodes.Newobj, typeof(HttpRequestMessage));
            il.Emit(OpCodes.Stloc, requestMessage);
            il.Emit(OpCodes.Ldloc_0);
            il.Emit(OpCodes.Call, typeof(HttpMethod).GetMethod($"get_{nameof(HttpMethod.Delete)}"));
       

            il.Emit(OpCodes.Nop);
            //    il.Emit(OpCodes.Call, typeof(Console).GetMethod("ReadLine"));
            //    il.Emit(OpCodes.Pop); // we just read something here, throw it.
            il.Emit(OpCodes.Ret);
            var helloKittyClassType = typeBuilder.CreateType();

            var console = System.Activator.CreateInstance(helloKittyClassType) as IRoleManage;
            console.Get(123);
  
    public class RoleManage : IRoleManage
    {
        private readonly HttpClient httpClient;

        public RoleManage(HttpClient httpClient)
        {
            this.httpClient = httpClient;
        }
        public void Delete(long id)
        {
            var requestMessage = new HttpRequestMessage();
            requestMessage.Method = HttpMethod.Delete;
            requestMessage.RequestUri = new Uri("/Role/" + id);
            var responseMessage = httpClient.Send(requestMessage);


            //  throw new NotImplementedException();
        }
        public void Save(RoleEntity entity)
        {
            throw new NotImplementedException();
        }
        public string Get(long id)
        {
            var responseMessage = httpClient.Send(new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri("/Role/" + id) });

            return responseMessage.Content.ReadAsStringAsync().Result;

        }
    }
    public interface IRoleManage
    {
        //  [Post("~/SystemManage/Role/DeleteFormJson/{id}")]
        // void Delete(long id);
        //    [Post("~/SystemManage/Role/SaveFormJson")]
        //    void Save(RoleEntity entity);

        string Get(long id);
    }
    public class RoleEntity
    {

    }
       */
}
